﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GomeeSoft.src.classes;
using GomeeSoft.src.control;

namespace GomeeSoft.src.form.DiaryPages
{
    public partial class UCScheduleL : UserControl
    {
        // Intialize **********************************************************************
        #region Initialize
        public UCScheduleL()
        {
            InitializeComponent();
            InitializeDesign();
            InitializeFrameList();
        }
        private void InitializeDesign()
        {
            BackColor = Color.White;
        }
        private void InitializeFrameList()
        {
            UCDataGrid.UCDataColumn c;
            c = new UCDataGrid.UCDataColumn("schedule_date", "Time", typeof(System.DateTime), 60, ContentAlignment.MiddleLeft);
            ucFrameList.AddDataColumn(c);
            c = new UCDataGrid.UCDataColumn("schedule_alarm", "Alarm", typeof(System.String), 60, ContentAlignment.MiddleLeft);
            ucFrameList.AddDataColumn(c);
            c = new UCDataGrid.UCDataColumn("schedule_repeat", "Repeat", typeof(System.String), 60, ContentAlignment.MiddleLeft);
            ucFrameList.AddDataColumn(c);
            c = new UCDataGrid.UCDataColumn("schedule_memo", "Memo", typeof(System.String), 300, ContentAlignment.MiddleLeft);
            ucFrameList.AddDataColumn(c);
        }
        #endregion

        // Resize *************************************************************************
        #region Resize
        private void UCScheduleL_Resize(Object sender, EventArgs e)
        {
            Point p = new Point(0, 57);
            Size s = new Size(Width, 192);
            ucFrameMonth.Location = p;
            ucFrameMonth.Size = s;
            p.Offset(0, ucFrameMonth.Height + 4);
            s = new Size(Width, Height - p.Y - 4);
            ucFrameList.Location = p;
            ucFrameList.Size = s;
        }
        #endregion

        // Paint **************************************************************************
        #region Paint
        private void UCScheduleL_Paint(object sender, PaintEventArgs e)
        {
            UCPage.PaintHeaderLine(sender, e, new Size(Width, Height));
        }
        #endregion

        // Business Logic *****************************************************************
        #region Business Logic
        private void ucFrameMonth_OnDateSelected(object sender, EventArgs e, DateTime d)
        {
            SQLiteQuery query = new SQLiteQuery();
            query.SetCommand(GomeeSoft.Properties.Resources.SQLScheduleList);
            query.SetParameter("@schedule", d);
            DataTable dt = query.SelectDataTable();
            ucFrameList.DataSource = dt;
        }
        #endregion
    }
}
